#ifndef _LIB_USOLIB
#define _LIB_USOLIB

var usoLib = $ = function(a, b) {
	return new usoLib.fn.init(a, b)
};
usoLib.fn = usoLib.prototype = {
	init: function(a, e) {
		a = a || document;
		e = e || document;
		if (a.nodeType) {
			a = [a]
		} else {
			if (typeof a == "string") {
				var d = a.split(" || "),
				a = [],
				c = 0,
				b = [];
				while (a = d[c++]) {
					if (a[0] === "#") {
						if (element = e.getElementById(a.substr(1))) {
							b = b.concat([element])
						}
					} else {
						if (a[0] === "/") {
							b = b.concat(this.xpath("." + a, e))
						} else {
							if (match = a.match(new RegExp("^(.*?)\\.(.*)$"))) {
								if (match[1] == "") {
									if (document.getElementsByClassName) {
										b = b.concat(this.make_array(e.getElementsByClassName(match[2])))
									} else {
										b = b.concat(this.xpath(".//*[contains(concat(' ',@class,' '),' " + match[2] + " ')]", e))
									}
								} else {
									b = b.concat(this.xpath(".//" + match[1] + "[contains(concat(' ',@class,' '),' " + match[2] + " ')]", e))
								}
							} else {
								b = b.concat(this.make_array(e.getElementsByTagName(a)))
							}
						}
					}
				}
				a = b
			}
		}
		return this.set_array((a.constructor.toString().indexOf("Array") !== -1) ? a: this.make_array(a))
	},
	set_array: function(a) {
		this.length = 0;
		Array.prototype.push.apply(this, a);
		return this
	},
	make_array: function(c) {
		var b = c.length,
		a = [];
		while (b) {
			a[--b] = c[b]
		}
		return a
	},
	xpath: function(f, d) {
		var e = d = d || document,
		b = [],
		c = 0;
		if (e != document) {
			e = d.ownerDocument
		}
		var a = e.evaluate(f, d, null, 7, null);
		while (element = a.snapshotItem(c++)) {
			b.push(element)
		}
		return b
	},
	each: function(a) {
		return usoLib.each(this, a)
	},
	get: function(a) {
		return this[a] ? usoLib(this[a]) : null
	},
	count: function() {
		return this.length
	},
	find: function(a) {
		if (this.length === 1) {
			return usoLib(a, this[0])
		}
		return usoLib(a)
	},
	hide: function(a) {
		if (typeof a === "number") {
			return this.animate({
				opacity: "0"
			},
			a, function() {
				usoLib(this).hide()
			})
		} else {
			return this.each(function() {
				this.$old_display = usoLib.get_style(this, "display");
				this.style.display = "none"
			})
		}
	},
	show: function(a) {
		if (typeof a === "number") {
			usoLib(this).css({
				opacity: "0",
				display: (this.$old_display ? this.$old_display: "")
			});
			return this.animate({
				opacity: "1"
			},
			a)
		} else {
			return this.each(function() {
				usoLib(this).css({
					display: (this.$old_display ? this.$old_display: ""),
					opacity: "1"
				})
			})
		}
	},
	css: function(a) {
		return this.each(function(c, b) {
			usoLib.each(a, function(d) {
				b.style[d] = this
			})
		})
	},
	bind: function(b, a) {
		return this.each(function() {
			this.addEventListener(b, a, false)
		})
	},
	remove: function() {
		return this.each(function() {
			this.parentNode.removeChild(this)
		})
	},
	append: function(a) {
		return this.each(function() {
			this.appendChild(a.cloneNode(true))
		})
	},
	html: function(a) {
		if (a) {
			return this.each(function() {
				this.innerHTML = a.toString();
			})
		} else {
			return this[0] ? this[0].innerHTML: null
		}
	},
	attr: function(a, b) {
		if (!a) {
			return
		} else {
			if (typeof b === "string") {
				return this.each(function() {
					this.setAttribute(a, b)
				})
			}
		}
		return this[0] ? this[0].getAttribute(a) : null
	},
	animate: function(d, e, f) {
		if (!this.animation_queue) {
			this.animation_queue = []
		}
		if (this.animating) {
			this.animation_queue.push(arguments);
			return this
		}
		this.animating = true;
		var a = 40,
		e = e ? Math.round(e * (1 / a)) * a: 1000,
		c = e / a,
		b = this;
		setTimeout(function(g) {
			g.animating = false;
			if (g.animation_queue.length > 0) {
				g.animate.apply(g, g.animation_queue[0]);
				g.animation_queue.shift()
			}
		},
		e + 1, this);
		return this.each(function() {
			var g = [],
			j = this,
			h = 0;
			usoLib.each(d, function(k) {
				var n = usoLib.get_style(j, k),
				i = /\d(px|%|in|em|pt|pc|ex)$/,
				m = (match = n.match(i)) ? match[1] : "",
				l = parseFloat(this);
				if (m != ((match = this.match(i)) ? match[1] : "")) {
					return
				} else {
					if (typeof(n = parseFloat(n)) !== "number") {
						return
					}
				}
				g.push({
					key: k,
					step: (l - n) / c,
					start: n,
					suffix: m
				})
			});
			j.timer = setInterval(function() {
				h++;
				usoLib.each(g, function() {
					j.style[this.key] = this.start + (this.step * h) + this.suffix
				});
				if (h === c) {
					clearInterval(j.timer);
					if (f && (f.constructor.toString().indexOf("Function") !== -1)) {
						f.call(j)
					}
				}
			},
			a)
		})
	},
	stop: function() {
		return this.each(function() {
			if (this.timer) {
				clearInterval(this.timer)
			}
		})
	}
};
usoLib.fn.init.prototype = usoLib.fn;
usoLib.each = function(b, f) {
	var c = 0,
	d = b.length,
	a;
	if (d === undefined) {
		for (a in b) {
			if (f.call(b[a], a, b[a]) === false) {
				break
			}
		}
	} else {
		for (var e = b[0]; c < d && f.call(e, c, e) !== false; e = b[++c]) {}
	}
	return b
};
usoLib.get_style = function(c, a) {
	if (c.style[a]) {
		return c.style[a]
	} else {
		if (c.currentStyle) {
			return c.currentStyle[a]
		} else {
			if (document.defaultView && document.defaultView.getComputedStyle) {
				var b = document.defaultView.getComputedStyle(c, "");
				return b && b.getPropertyValue(a.replace(/([A-Z])/g, "-$1").toLowerCase())
			} else {
				return null
			}
		}
	}
};
usoLib.fn.slide_out = function() {
	return this.each(function() {
		usoLib(this).css({
			overflow: "hidden"
		}).animate({
			height: "0px",
			opacity: "0"
		},
		100, function() {
			usoLib(this).attr('style', '').hide();
		});
	});
};
Array.prototype.remove = function(from, to) {
	this.length = from < 0 ? this.length + from: from;
	return this.push.apply(this, this.slice((to || from) + 1 || this.length));
};
String.prototype.ucwords = function() {
	return (this + '').replace(/^(.)|\s(.)/g, function($1) {
		return $1.toUpperCase();
	});
};
#endif
